package com.hz.house.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hz.house.service.WxgzhBuyHouseService;

/**
 * <p> 腾讯微信公众号开发接口
 * @author flw
 */
@RestController
@RequestMapping("/wxgzh/buy/msg")
public class WxgzhBuyHouseController {


    @Autowired
    private WxgzhBuyHouseService buyHouseService;

    /**
     * 	成都买房帮手服务号消息推送过来
     * @return
     */
    @RequestMapping("/wxmsg")
    public String wxgzhMsgCallback(HttpServletRequest req) {
        String method = req.getMethod();
        //验证token
        if(method.equals("GET")) 
            return buyHouseService.validateToken(req);
        //其余post
        buyHouseService.handlebuyHouseWxgzhCallBack(req);
        return "success";
    }

    /**
     * 	成都买房帮手 置业顾问网页授权获取unionid绑定小程序置业顾问openid实现消息回复推送
     * @param req
     * @param mv
     */
    @RequestMapping("/ugzhBindXcx")
    public void wxgzhAuth2Callback(HttpServletRequest req,HttpServletResponse rep) {

        int res = this.buyHouseService.wxgzhAuth2Callback(req);
        //返回值判定再跳转到哪个
        String page = "http://www.fangjiadianpingbang.com/gzh/";
        switch(res) {
            case 0:
                //错误
                page+="error.html";
                break;
            case 1:
                //登录重试
                page+="retry.html";
                break;
            case 2:
                //成功
                page+="success.html";
                break;
        }
        try {
            //直接跳转到结束提示页
            rep.sendRedirect(page);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
